package edu.imac.angryfood.states;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.gui.MouseOverArea;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
import org.newdawn.slick.state.transition.FadeInTransition;
import org.newdawn.slick.state.transition.FadeOutTransition;

import edu.imac.angryfood.game.Angryfood;

/**
 * 
 * the state of the credits
 *
 */
public class CreditState extends BasicGameState implements ComponentListener{
	
	public static int ID;
	public Angryfood parent;
	private StateBasedGame game;
	
	/** The areas defined */
	private MouseOverArea[] areas;
	/** The logo of the game */
	private Image logo;
	/** The background image */
	private Image background;
	/** The credit image */
	private Image credit;
	/** The button image */
	private Image border; 

	

	
	public CreditState(Angryfood game, int ID) {
		super();
		CreditState.ID = ID;
		this.parent = game;

	}
	
	/** initializes the game
	 * @param container contains the game
	 * @param game the game
	 * @throws SlickException
	 */
	
	public void init(GameContainer container, StateBasedGame game) throws SlickException {
		this.game = game;	
		
		
		/** Initialization of the images */
		logo =  new Image("res/img/menu/logoAF.png");
		credit =  new Image("res/img/game/credits.png");
		background = new Image("res/img/menu/fondAF.jpg");
		border = new Image("res/img/menu/cadre.png"); 

		/** Area that can be clicked */
		areas = new MouseOverArea[1];		
		
		areas[0] = new MouseOverArea(container, border, 180 , 500 , 200, 50, this);
		areas[0].setNormalColor(new Color(1,1,1,0.8f));
		areas[0].setMouseOverColor(new Color(1,1,1,1f));
		
	}
	
	/** render the graphics in slick
	 * @param container contains the game
	 * @param game the game
	 * @param g the graphics
	 */

	public void render(GameContainer container, StateBasedGame game, Graphics g) {
		
		/** Draw of the images*/
		background.draw(0, 0, 800, 600);
		logo.draw(400,0,400,100);
		credit.draw(50,80,500,392);
		
		areas[0].render(container, g);
		g.drawString("Retour", 250  , 510 ); 
			
		
	}

	/** update the physic world
	 * @param container the game container
	 * @param game the game
	 * @param delta
	 */	
	public void update(GameContainer container, StateBasedGame game, int delta) {
	}


	/**
     * Function used to click on the areas
     * 
     * @param source Area of the screen which is clicked
     */
	
	@Override
	public void componentActivated(AbstractComponent source) {	
			if (source == areas[0]) 
				game.enterState(0, new FadeOutTransition(Color.black), new FadeInTransition(Color.black));	

		
	}
		
	
	@Override
	public int getID() {
		return CreditState.ID;
	}


}
